//读取二进制xxx.bin文件并逐个字节解析//2019.11.10
#include <iostream>
#include <fstream>
#include <vector>
#include "stdio.h"
using namespace std;

int main(int argc, char **argv)
{

    size_t length;
    ifstream inF;

    inF.open("data.bin", std::ifstream::binary); //以二进制格式打开文件
    inF.seekg(0, ios::end);                      //将输入指针指向文件末尾
    length = inF.tellg();                        //获取当前指针位置
    cout << "the length of the file is " << length << " "
         << "byte" << endl;

    unsigned char *data = new unsigned char[100](); //读取文件数组
    inF.seekg(0, ios::beg);                         //将输入指针指向文件开头
    // inF.get();
    if (!inF.eof())
    {
        cout << "target reading..." << endl;
        inF.read(reinterpret_cast<char *>(data), sizeof(char) * length); //读入文件流
        cout << "finished reading" << endl;
    }
    inF.close(); //关闭文件

    for (size_t i = 0; i < 10; i++)
    {
        // cout <<hex<< data[i] ;
        printf("%#X ", data[i]);
    }
    cout << endl;

    cout << "finished parsing" << endl;
}